﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace AAA.Base.Util.SafeCollection
{
    public class ThreadSafeDictionary<T1, T2>
    {
        private Dictionary<T1, T2> _dicSource = new Dictionary<T1,T2>();

        public void Add(T1 key, T2 value)
        {
            lock (((ICollection)_dicSource).SyncRoot)
            {
                _dicSource.Add(key, value);
            }
        }

        public void Remove(T1 key)
        {
            lock (((ICollection)_dicSource).SyncRoot)
            {
                _dicSource.Remove(key);
            }
        }

        public T2 this[T1 key]
        {
            get { return _dicSource[key]; }
            set { _dicSource[key] = value; }
        }

        public bool ContainsKey(T1 key)
        {                        
            return _dicSource.ContainsKey(key);
        }

        public Dictionary<T1, T2>.KeyCollection Keys
        {
            get { return _dicSource.Keys; }
        }

        public Dictionary<T1, T2>.ValueCollection Values
        {
            get { return _dicSource.Values; }
        }
    }
}
